package org.wutopia.labcloud.domain.uaa.config.httpclient;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.net.ProxySelector;
import java.net.http.HttpClient;
import java.time.Duration;

@Configuration
public class HttpClientConfig {

    @Bean
    public HttpClient getClient() {

        HttpClient client = HttpClient.newBuilder()
                .version(HttpClient.Version.HTTP_1_1)    // 默认 HTTP/2
                .connectTimeout(Duration.ofSeconds(10))
                .followRedirects(HttpClient.Redirect.ALWAYS) // 自动重定向
                .proxy(ProxySelector.getDefault())     // 使用系统代理
                .build();
        return client;
    }

    @Bean
    public RestTemplate getRest() {
        return new RestTemplate();
    }
}
